package com.ruoyi.web.controller.mes;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.pinyin.PinYinUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.web.domain.MesBindingAllocation;
import com.ruoyi.web.domain.mes.MesMachinePaper;
import com.ruoyi.web.mapper.MesConfigMapper;
import com.ruoyi.web.mapper.ProduceMapper;
import com.ruoyi.web.service.*;
import com.ruoyi.web.service.Impl.MesBindingDailyNewServiceImpl;
import com.ruoyi.web.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/bindingdaily")
public class MesBindingDailyController extends BaseController {

    @Resource
    private MesBindingDailyService mesBindingDailyService;
    @Resource
    private MesBindingDailyStaffService mesBindingDailyStaffService;
    @Resource
    private MesBindingDailyDetailService mesBindingDailyDetailService;
    @Resource
    private MesConfigMapper configMapper;
    @Resource
    private IMesReportWork MesReportWork;
    @Resource
    private MesMachineService mesMachineService;
    @Resource
    private ProduceMapper produceMapper;
    @Resource
    private ProducePieceService producePieceService;
    @Resource
    private MesProducePieceMachineService producePieceMachineService;
    @Resource
    private ProduceService produceService;
    @Resource
    private MesQualityService mesQualityService;
    @Resource
    private MesQualityUserService mesQualityUserService;
    @Resource
    private MesQualityWorkService mesQualityWorkService;
    @Resource
    private ProducePrintService producePrintService;

    @Resource
    private ProduceProductService produceProductService;

    @Resource
    private ReportService reportService;

    @Autowired
    private MesBindingDailyNewServiceImpl MesBindingDailyNewService;

    @Resource
    private MesBindingAllocationService mesBindingAllocationService;


    //    @PostMapping(value = "/list")
    @GetMapping("/getmesbindlist")
    public TableDataInfo list(MesBindingDaily mesBindingDaily) {

        startPage();  // 此方法配合前端完成自动分页
        List<MesBindingDaily> data = MesBindingDailyNewService.GetMesBindingDailyList(mesBindingDaily);
//        startPage(params);
//        String bindingNo = params.get("bindingNo");//编号
//        String dailyDate = params.get("dailyDate");//时间
//        String  workshopName=params.get("workshopName");
//        String   status=params.get("status");


//        TableDataInfo data = getDataTable(mesBindingDailyService.list(new QueryWrapper<MesBindingDaily>().lambda()
//                .like(StringUtils.isNotEmpty(bindingNo), MesBindingDaily::getBindingNo, bindingNo)
//                .like(StringUtils.isNotEmpty(dailyDate), MesBindingDaily::getDailyDate, dailyDate)
////                .like(StringUtils.isNotEmpty(workshopName), MesBindingDaily::getDailyDate, dailyDate)
//                .orderByDesc(MesBindingDaily::getCreateTime)
//        ));
        return getDataTable(data);
    }

    @PostMapping(value = "/getById")
    public AjaxResult getById(@RequestBody Map<String, String> params) {
        String id = params.get("id");
        MesBindingDaily mesBindingDaily = mesBindingDailyService.getById(id);
        String machineId = mesBindingDaily.getMachineId();
        String machineType = "";
        MesMachine mesMachine = mesMachineService.getById(machineId);
        if (mesMachine != null) {
            machineType = mesMachine.getType();
        }
        //员工信息
        List<MesBindingDailyStaff> mesBindingDailyStaffs = mesBindingDailyStaffService
                .list(new QueryWrapper<MesBindingDailyStaff>()
                        .lambda().like(MesBindingDailyStaff::getBindingDailyId, mesBindingDaily.getId()));
        //详情
        List<MesBindingDailyDetail> mesBindingDailyDetails = mesBindingDailyDetailService
                .list(new QueryWrapper<MesBindingDailyDetail>()
                        .lambda().like(MesBindingDailyDetail::getBindingDailyId, mesBindingDaily.getId())
                        .orderByAsc(MesBindingDailyDetail::getBreedType));

        mesBindingDaily.setBindingDailyStaffs(mesBindingDailyStaffs);
        mesBindingDaily.setBindingDailyDetails(mesBindingDailyDetails);

//        // 循环查询累计上报数量 和 最大允许上报量
//        String failureMsg = MesReportWork.selectMesReportTotalNum(mesBindingDaily, machineId, machineType);  // 装订报工
//        if (StringUtils.isNotEmpty(failureMsg)) {
//            return AjaxResult.warn(failureMsg);
//        }
        return AjaxResult.success("查询成功", mesBindingDaily);
    }

    @PostMapping(value = "/add")
    @Transactional
    public AjaxResult add(@RequestBody MesBindingDaily mesBindingDaily) {
        String Id = UUID.randomUUID().toString().replace("-", "");

        Map<String, Object> map = new HashMap<>();
        map.put("columnName", "binding_no");
        map.put("tableName", "mes_binding_daily");
        int maxNum = configMapper.getMouthMaxId(map);
        String No = PinYinUtils.getCodeNormal(maxNum, "ZDRB");

        mesBindingDaily.setCreateTime(DateUtils.getNowDate());
        mesBindingDaily.setId(Id);
        mesBindingDaily.setBindingNo(No);

//        // 判断当前步骤的报工量不能大于上一步骤的报工量
//        String failureMsg = MesReportWork.checkMesReportPreviousStep(mesBindingDaily, "3");  // 装订报工
//        if (StringUtils.isNotEmpty(failureMsg)) {
//            return AjaxResult.warn(failureMsg);
//        }

        // 上报主表机台id
        String machineId = mesBindingDaily.getMachineId();
        MesMachine mesMachine = mesMachineService.getById(machineId);
        String machineType = mesMachine.getType();

        mesBindingDailyService.saveOrUpdate(mesBindingDaily);
        if (mesBindingDaily.getBindingDailyStaffs() != null && mesBindingDaily.getBindingDailyStaffs().size() != 0) {
            for (MesBindingDailyStaff staff : mesBindingDaily.getBindingDailyStaffs()) {
                staff.setId(UUID.randomUUID().toString().replace("-", ""));
                staff.setBindingDailyId(Id);
            }
            mesBindingDailyStaffService.saveBatch(mesBindingDaily.getBindingDailyStaffs());
        }
        List<String> productIdList=new ArrayList<>();
        if (mesBindingDaily.getBindingDailyDetails() != null && mesBindingDaily.getBindingDailyDetails().size() != 0) {
            for (MesBindingDailyDetail detail : mesBindingDaily.getBindingDailyDetails()) {
                detail.setId(UUID.randomUUID().toString().replace("-", ""));
                detail.setBindingDailyId(Id);
                productIdList.add(detail.getProductId());
            }
            mesBindingDailyDetailService.saveBatch(mesBindingDaily.getBindingDailyDetails());
           //取消暂提
            String productIds=String.join(",",productIdList);
             produceMapper.updateTempStatus(productIds);
        }

        if (mesBindingDaily.getBindingDailyDetails() != null && mesBindingDaily.getBindingDailyDetails().size() != 0) {
            for (MesBindingDailyDetail mesBindingWork : mesBindingDaily.getBindingDailyDetails()) {
                // 过胶
                if (mesBindingDaily.getBindingType().equals("2")) {
                    // 更新生产单产品中的过胶状态
                    produceProductService.update(new UpdateWrapper<ProduceProduct>().lambda().set(ProduceProduct::getIsGj, "1").eq(ProduceProduct::getProductId, mesBindingWork.getProductId()));
                    continue;
                }

                MesMachine mesMachineBind = new MesMachine();
                mesMachineBind.setPid(machineId);
                mesMachineBind.setModel(mesBindingWork.getProduceId());
                mesMachineBind.setEra(mesBindingWork.getProductId());
                List<ProducePiece> pieceList = produceMapper.bindingPiece(mesMachineBind);

                if (pieceList.size() == 0) {
                    throw new ServiceException("没有查到该产品的贴信息！");
                }

                // 贴数id集合
                List<String> pieceIds = new ArrayList<>();
                // 累计上报量
                BigDecimal totalNum = reportService.selectTotalNumBinding(mesBindingWork.getProductId(), machineId, "");
                // 订单数量 * 0.99
                BigDecimal orderJS = mesBindingWork.getOrderCount().multiply(new BigDecimal(0.99));
                if (totalNum.compareTo(orderJS) >= 0) {
                    String state = "2";
                    if (pieceList.size() > 0) {
                        pieceIds = pieceList.stream().map(it -> it.getPieceId()).collect(Collectors.toList());
                        producePieceService
                                .update(new UpdateWrapper<ProducePiece>().lambda()
                                        .set(ProducePiece::getBindingState, state)
                                        .in(ProducePiece::getPieceId, pieceIds)
                                );

                        for (ProducePiece producePiece : pieceList) {
                            producePiece.setBindingState("2");
                            int num = 0;
                            List<MesProducePieceMachine> list = producePieceMachineService.list(new QueryWrapper<MesProducePieceMachine>()
                                    .lambda().eq(MesProducePieceMachine::getPieceId, producePiece.getPieceId()));
                            //先查询中间表是否全部完成
                            for (MesProducePieceMachine item : list) {
                                if (item.getMachineType().equals("2")) {    //印刷机
                                    if (String.valueOf(producePiece.getPressState()).equals("2")) {
                                        num++;
                                    }
                                } else if (item.getMachineType().equals("6") || item.getMachineType().equals("5")) {  //封面裁切
                                    if (String.valueOf(producePiece.getTrimmingState()).equals("2")) {
                                        num++;
                                    }
                                } else if (item.getMachineType().equals("4")) { //折页
                                    if (String.valueOf(producePiece.getFoldState()).equals("2")) {
                                        num++;
                                    }
                                } else if (item.getMachineType().equals("7")) {   //覆膜
                                    if (String.valueOf(producePiece.getCoveringState()).equals("2")) {
                                        num++;
                                    }
                                } else if (item.getMachineType().equals("3")) {   //装订
                                    if (String.valueOf(producePiece.getBindingState()).equals("2")) {
                                        num++;
                                    }
                                }
                            }
                            if (num == list.size()) {
                                // 更改帖数表总的状态
                                producePieceService.update(new UpdateWrapper<ProducePiece>().lambda().set(ProducePiece::getPrintStatus, "2").eq(ProducePiece::getPieceId, producePiece.getPieceId()));
                            }
                        }
                        // 更新生产单产品状态
                        produceProductService.update(new UpdateWrapper<ProduceProduct>().lambda().set(ProduceProduct::getBindingStatus, "1").eq(ProduceProduct::getProductId, mesBindingWork.getProductId()));
                    }

                }

                // 更新生产单状态为各工序进行中
                int produceStatus = 15; // 装订中
                Produce produceCurrentIng = produceService.getById(mesBindingWork.getProduceId());
                if (produceCurrentIng != null) {
                    String produceCurrentStatus = produceCurrentIng.getStatus() == null ? "" : produceCurrentIng.getStatus();
                    if (!produceCurrentStatus.equals("17") && !produceCurrentStatus.equals("18")) {
                        produceService.update(new UpdateWrapper<Produce>().lambda().set(Produce::getStatus, produceStatus)
                                .eq(Produce::getProduceId, mesBindingWork.getProduceId()));
                    }
                }

                // 按每个有装订工艺的内文生产单品种查询,如果每个品种装订数量大于等于生产单数量,修改生产单状态为装订完成
                boolean productCompleteNum = true; // 订单所有品种报工完成
                ProduceProduct technologyProduct = new ProduceProduct();
                technologyProduct.setProduceId(mesBindingWork.getProduceId());
                List<ProduceProduct> technologyProductList = produceMapper.bindingTechnologyProduct(technologyProduct);
                for (ProduceProduct productItem : technologyProductList) {
                    List<MesBindingDailyDetail> techonlogyDetailList = mesBindingDailyDetailService.list(new QueryWrapper<MesBindingDailyDetail>().lambda()
                            .eq(MesBindingDailyDetail::getProduceId, productItem.getProduceId())
                            .eq(MesBindingDailyDetail::getProductId, productItem.getProductId())
                    );
                    List<BigDecimal> compList = techonlogyDetailList.stream().map(it -> it.getCompleteCount()).collect(Collectors.toList());
                    Long orderCount = Long.valueOf(0L);
                    Long total = Long.valueOf(0L);
                    if (techonlogyDetailList.size() > 0) {
                        orderCount = (long) techonlogyDetailList.get(0).getOrderCount().doubleValue();
                        total = (long) compList.stream().mapToDouble(bd -> bd.doubleValue()).sum();
                    }
                    if (total < orderCount || total == 0L) {
                        productCompleteNum = false;
                    }
                }

                if (productCompleteNum) {
                    int produceStatus1 = 16; // 装订完成
                    // 更改生产单状态
                    if (produceCurrentIng != null) {
                        String produceCurrentStatus = produceCurrentIng.getStatus() == null ? "" : produceCurrentIng.getStatus();
                        if (!produceCurrentStatus.equals("17") && !produceCurrentStatus.equals("18")) {
                            produceService.update(new UpdateWrapper<Produce>().lambda().set(Produce::getStatus, produceStatus1).eq(Produce::getProduceId, mesBindingWork.getProduceId()));
                        }
                    }
                }

//                List<String> produceIds = pieceList.stream().map(it -> it.getProduceId()).collect(Collectors.toList());
//                Set produceIdsSet = new HashSet(produceIds);
//                produceIds.clear();
//                produceIds.addAll(produceIdsSet);
//
//                // 遍历.查看生产单中是否存在未完成的帖,如果不存在更新生产单状态
//                for (String item : produceIds) {
//                    List<Map<String, Object>> countlist = producePieceService.listMaps(new QueryWrapper<ProducePiece>().lambda()
//                            .eq(ProducePiece::getProduceId, item)
//                            .eq(ProducePiece::getBindingState, "2").isNotNull(ProducePiece::getBindingState));
//                    ProducePiece piece = new ProducePiece();
//                    piece.setProduceId(item);
//                    piece.setMachineType("3");
//                    Integer resultNum = produceMapper.getPieceCount(piece);
//                    int countlistsum = (resultNum != null) ? resultNum : 0;
//                    // List<Map<String, Object>> countlistsum = producePieceService.listMaps(new QueryWrapper<ProducePiece>().lambda().eq(ProducePiece::getProduceId, item));
//                    if (countlist.size() > 0 && countlist.size() == countlistsum) {
//                        int produceStatus1 = 16; // 装订完成
//                        // 更改生产单状态
//                        Produce produceCurrent = produceService.getById(item);
//                        if (produceCurrent != null) {
//                            String produceCurrentStatus = produceCurrent.getStatus() == null ? "" : produceCurrent.getStatus();
//                            if (!produceCurrentStatus.equals("17") && !produceCurrentStatus.equals("18")) {
//                                produceService.update(new UpdateWrapper<Produce>().lambda().set(Produce::getStatus, produceStatus1).eq(Produce::getProduceId, item));
//                            }
//                        }
//                    }
//                }

                // 相对应的封面生产单，中的生产数量需要减装订填写的完成数量，计算出剩余数量
                ProduceProduct produceProduct = produceProductService.getById(mesBindingWork.getProductId());
                String productIds = produceProduct.getProduceIds();
                if (StringUtils.isNotEmpty(productIds)) {
                    List<String> listProductIds = new ArrayList<>();
                    String[] split = productIds.split(",");
                    for (String s : split) {
                        listProductIds.add(s);
                    }
                    List<ProduceProduct> listProduceProduct = produceProductService.list(new QueryWrapper<ProduceProduct>().lambda().in(ProduceProduct::getProductId, listProductIds));
                    for (ProduceProduct productItem : listProduceProduct) {
                        BigDecimal coutConmlete = mesBindingWork.getCompleteCount();

                        ProduceProduct produceProductItem = new ProduceProduct();
                        produceProductItem.setProduceId(productItem.getProduceId());
                        produceProductItem.setProductId(productItem.getProductId());
                        produceProductItem.setCompleteCount(coutConmlete);
                        produceProductItem.setType((long) 2);
                        // 修改剩余数量
                        produceMapper.updateProductCount(produceProductItem);

                    }
                }
            }
        }

        //region 装订分配机台

        List<MesMachine> MesMachine = produceMapper.getbindingcount(machineId);
        if(MesMachine!=null&&MesMachine.size()>0){
            //任务量大于20000不分配
        }else {
            //获取报工的车间
            String workshopId = mesMachine.getWorkshopId();
            //装订二车间对印刷一车间
            if (Objects.equals(workshopId, "8")) {
                workshopId = "7";
            } else {
                workshopId = "10";
            }
            //装订分配机台规则表
            MesBindingAllocation binding = new MesBindingAllocation();
            List<MesBindingAllocation> bindingAllocations = mesBindingAllocationService.list(new QueryWrapper<MesBindingAllocation>().lambda()
                    .like(MesBindingAllocation::getMachineId, machineId));
            if (bindingAllocations != null && bindingAllocations.size() > 0) {
                if (bindingAllocations.size() == 1) {
                    binding = bindingAllocations.get(0);
                } else {
                    binding.setPrintWorkshopId(workshopId);
                    binding.setBindingMode(bindingAllocations.get(0).getBindingMode());
                }
            }
            //查询一条装订待分配生产单
            List<Produce> produces = produceMapper.bindingProduceId(binding);
            if (produces != null && produces.size() > 0) {
                //分配装订机台
                produceService.BindingMachine(produces.get(0).getProduceId());
            } else {
                //当前车间如果没有可分配的去除车间条件
                MesBindingAllocation binds = new MesBindingAllocation();
                List<Produce> produce1 = produceMapper.bindingProduceId(binds);
                if (produce1 != null && produce1.size() > 0) {
                    produceService.BindingMachine(produce1.get(0).getProduceId());
                }
            }
        }
        //endregion



        return AjaxResult.success("添加成功", mesBindingDaily.getId());
    }




    @PostMapping(value = "/updateStatus")
    @Transactional
    public AjaxResult updateStatus(@RequestBody Map<String, String> params) {
        String id = params.get("id");
        String status = params.get("status");

        // 上报主表机台类型
        String machineType = params.get("machineType");
        MesBindingDaily mesBindingDaily = mesBindingDailyService.getById(id);
        // 上报主表机台id
        String machineId = mesBindingDaily.getMachineId();
        MesMachine mesMachine = mesMachineService.getById(machineId);
        if (StringUtils.isEmpty(machineType) && mesMachine != null) {
            machineType = mesMachine.getType();
        }

        if (status.equals("1")) { // 车间主任审核通过
//            List<MesBindingDailyDetail> bindingWorkList = mesBindingDailyDetailService.list(new QueryWrapper<MesBindingDailyDetail>().lambda().eq(MesBindingDailyDetail::getBindingDailyId, id));
//            List<MesBindingDailyStaff> bindingtUserList = mesBindingDailyStaffService.list(new QueryWrapper<MesBindingDailyStaff>().lambda().eq(MesBindingDailyStaff::getBindingDailyId, id));


//            // 查询有质量事故的完成工作量明细，插入到质量管理模块
//            List<MesBindingDailyDetail> qualityWorklist = bindingWorkList.stream().filter(it -> it.getAccident().equals("1")).collect(Collectors.toList());
//            if (qualityWorklist.size() > 0) {
//                // 插入主表
//                MesQuality mesQuality = new MesQuality();
//                // 生成质量处理单id
//                mesQuality.setId(UUID.randomUUID().toString().replace("-", ""));
//
//                // 生成质量处理单编号
//                Map<String, Object> map = new HashMap<>();
//                map.put("columnName", "code");
//                map.put("tableName", "mes_quality");
//                int maxNum = configMapper.getMouthMaxId(map);
//                String code = PinYinUtils.getCodeNormal(maxNum, "ZLCL");
//
//                mesQuality.setReportId(mesBindingDaily.getId());
//                mesQuality.setCode(code);
//                mesQuality.setMachineId(machineId);
//                mesQuality.setMachineName(mesBindingDaily.getMachineName());
//                mesQuality.setHeadId(mesBindingDaily.getHeadId());
//                mesQuality.setHeadName(mesBindingDaily.getHeadName());
//                mesQuality.setStatus(1); // 未提交
//                mesQuality.setDisposeType("4");  // 装订报工
//                mesQuality.setCreateBy(SecurityUtils.getUsername());
//                mesQuality.setCreateTime(DateUtils.getNowDate());
//                // 插入质量主表
//                mesQualityService.save(mesQuality);
//
//                List<MesQualityUser> mesQualityUserList = new ArrayList<>();
//                for (MesBindingDailyStaff qualitytUser : bindingtUserList) {
//                    MesQualityUser mesQualityUser = new MesQualityUser();
//                    mesQualityUser.setQualityId(mesQuality.getId());
//                    mesQualityUser.setNo(qualitytUser.getStaffNum());
//                    mesQualityUser.setName(qualitytUser.getStaffName());
//                    mesQualityUser.setWagesPiece(qualitytUser.getPieceWages());
//                    mesQualityUser.setCreateBy(SecurityUtils.getUsername());
//                    mesQualityUser.setCreateTime(DateUtils.getNowDate());
//                    mesQualityUserList.add(mesQualityUser);
//                }
//                // 批量插入罚款人员
//                mesQualityUserService.saveBatch(mesQualityUserList);
//
//                List<MesQualityWork> mesQualityWorklist = new ArrayList<>();
//                for (MesBindingDailyDetail qualityWork : qualityWorklist) {
//                    MesQualityWork mesQualityWork = new MesQualityWork();
//                    mesQualityWork.setQualityId(mesQuality.getId());
//                    BeanUtils.copyProperties(qualityWork, mesQualityWork);
//                    mesQualityWork.setCreateBy(SecurityUtils.getUsername());
//                    mesQualityWork.setCreateTime(DateUtils.getNowDate());
//                    mesQualityWorklist.add(mesQualityWork);
//                }
//                // 批量插入完成工作量明细
//                mesQualityWorkService.saveBatch(mesQualityWorklist);
//            }

        }
        // 更新报工单状态
        mesBindingDailyService.update(new UpdateWrapper<MesBindingDaily>().lambda().set(MesBindingDaily::getStatus, status).eq(MesBindingDaily::getId, id));
        return AjaxResult.success("");
    }

    @PostMapping(value = "/deleteById")
    public AjaxResult deleteById(@RequestBody Map<String, String> params) {
        String id = params.get("id");
        mesBindingDailyService.removeById(id);
        mesBindingDailyStaffService.remove(new QueryWrapper<MesBindingDailyStaff>().lambda()
                .eq(MesBindingDailyStaff::getBindingDailyId, id));

        mesBindingDailyDetailService.remove(new QueryWrapper<MesBindingDailyDetail>().lambda()
                .eq(MesBindingDailyDetail::getBindingDailyId, id));
        return AjaxResult.success("删除成功");
    }


    @PostMapping(value="/update")
    public AjaxResult update(@RequestBody MesBindingDaily mesBindingDaily){

        String id =mesBindingDaily.getId();
        mesBindingDailyStaffService.remove(new QueryWrapper<MesBindingDailyStaff>().lambda()
                .eq(MesBindingDailyStaff::getBindingDailyId, id));

        mesBindingDailyDetailService.remove(new QueryWrapper<MesBindingDailyDetail>().lambda()
                .eq(MesBindingDailyDetail::getBindingDailyId, id));

        if (mesBindingDaily.getBindingDailyStaffs() != null && mesBindingDaily.getBindingDailyStaffs().size() != 0) {
            for (MesBindingDailyStaff staff : mesBindingDaily.getBindingDailyStaffs()) {
                staff.setId(UUID.randomUUID().toString().replace("-", ""));
                staff.setBindingDailyId(id);
            }
            mesBindingDailyStaffService.saveBatch(mesBindingDaily.getBindingDailyStaffs());
        }
        List<String> productIdList=new ArrayList<>();
        if (mesBindingDaily.getBindingDailyDetails() != null && mesBindingDaily.getBindingDailyDetails().size() != 0) {
            for (MesBindingDailyDetail detail : mesBindingDaily.getBindingDailyDetails()) {
                detail.setId(UUID.randomUUID().toString().replace("-", ""));
                detail.setBindingDailyId(id);
                productIdList.add(detail.getProductId());
            }
            mesBindingDailyDetailService.saveBatch(mesBindingDaily.getBindingDailyDetails());
        }
        return AjaxResult.success("保存成功");
    }
}
